Help with setting attribute in all modules

Here is my scenario:
I have an attribute called Reuse and wanted to set the test method to D in every module (have 50 modules) without opening them up manually if the Reuse is equal to New or Mod. Is this possible?

Thanks
vppatel - Fri May 13 11:42:57 EDT 2011

Re: Help with setting attribute in all modules
SystemAdmin - Sun May 15 05:40:29 EDT 2011

Try the following script - may need some further customisations here and there to suit your specific needs but should do it.
 

Module m
Object o
Item i
int x
string itemType
string modName, fullModName
string attrDefName1 = "Reuse"
string attrDefName2 = "Test Method"
string testMethod = "D"
 
for i in current Project do
    {
 
        itemType = type i
 
        if( itemType == "Formal")
                {
 
                fullModName = fullName(i)
                modName = name(i)               
                m = edit(fullModName,false)
                x = 0
 
                if (m == null) { //problem detected with opening the module
                        print modName ":\t ERROR - could not open module\n"  
                        continue
                        }     
                
                current = m
 
                if ((exists attribute attrDefName1) && (exists attribute attrDefName2)) {
                        for o in current do {
                                if ((o.attrDefName1"" == "New")||(o.attrDefName1"" == "Mod"))  {
                                        o.attrDefName2 = testMethod                             
                                        x++   //count each change being made
                                        save(m)
                                        }
                                }
                 }
                else {
                        print modName ":\t Does not contain one or both attributes\n"
                        close(m)
                        continue
                        }
 
                close(m)
                print  modName ":\t" x " changes applied\n"
                }
        }

 

 


Paul Miller
Melbourne, Australia

 

 

Re: Help with setting attribute in all modules
vppatel - Mon May 16 09:36:43 EDT 2011

Thanks Paul...

I added so that if the requirement is true that it will only set the attribute Test Method to "D" but it still does the non reqt objects as well. What am I doing incorrect?
 

Module m
Object o
Item i
int x
string itemType
string modName, fullModName
string attrDefName1 = "Reuse"
string attrDefName2 = "CSCI Test Method"
string attrDefName3 = "Requirement"
string testMethod = "D"
 
for i in current Folder do
    {
 
        itemType = type i
 
        if( itemType == "Formal")
                {
 
                fullModName = fullName(i)
                modName = name(i)               
                m = edit(fullModName,false)
                x = 0
 
                if (m == null) { //problem detected with opening the module
                        print modName ":\t ERROR - could not open module\n"  
                        continue
                        }     
                
                current = m
 
                if ((exists attribute attrDefName1) && (exists attribute attrDefName2)) {
                        for o in current do {
                                if ((o.attrDefName1"" == "New")||(o.attrDefName1"" == "Modified") && (o.attrDefName3"" == "True")) {
                                        o.attrDefName2 = testMethod                             
                                        x++   //count each change being made
                                        save(m)
                                        }
                                }
                 }
                else {
                        print modName ":\t Does not contain one or both attributes\n"
                        close(m)
                        continue
                        }
 
                close(m)
                print  modName ":\t" x " changes applied\n"
                }
        }

Re: Help with setting attribute in all modules
Mathias Mamsch - Mon May 16 10:02:12 EDT 2011

SystemAdmin - Sun May 15 05:40:29 EDT 2011

Try the following script - may need some further customisations here and there to suit your specific needs but should do it.
 

Module m
Object o
Item i
int x
string itemType
string modName, fullModName
string attrDefName1 = "Reuse"
string attrDefName2 = "Test Method"
string testMethod = "D"
 
for i in current Project do
    {
 
        itemType = type i
 
        if( itemType == "Formal")
                {
 
                fullModName = fullName(i)
                modName = name(i)               
                m = edit(fullModName,false)
                x = 0
 
                if (m == null) { //problem detected with opening the module
                        print modName ":\t ERROR - could not open module\n"  
                        continue
                        }     
                
                current = m
 
                if ((exists attribute attrDefName1) && (exists attribute attrDefName2)) {
                        for o in current do {
                                if ((o.attrDefName1"" == "New")||(o.attrDefName1"" == "Mod"))  {
                                        o.attrDefName2 = testMethod                             
                                        x++   //count each change being made
                                        save(m)
                                        }
                                }
                 }
                else {
                        print modName ":\t Does not contain one or both attributes\n"
                        close(m)
                        continue
                        }
 
                close(m)
                print  modName ":\t" x " changes applied\n"
                }
        }

 

 


Paul Miller
Melbourne, Australia

 

 

I see a couple of things on this script:
  • you should do "for o in current Module" since there is a "for o in Object do" loop also! So DXL could mistake the current for current Object.
  • Don't save after every modification, this will drastically increase runtime. Just set a boolean if any changes were made and save the module before closing it.
  • Take into account a default view with a filter, by looping with "for o in entire Module do { if (isDeleted o || table o || cell o || row o) continue; ... }"
  • Check if you really want to take into account table cells...

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Help with setting attribute in all modules
vppatel - Mon May 16 15:17:54 EDT 2011

vppatel - Mon May 16 09:36:43 EDT 2011

Thanks Paul...

I added so that if the requirement is true that it will only set the attribute Test Method to "D" but it still does the non reqt objects as well. What am I doing incorrect?
 

Module m
Object o
Item i
int x
string itemType
string modName, fullModName
string attrDefName1 = "Reuse"
string attrDefName2 = "CSCI Test Method"
string attrDefName3 = "Requirement"
string testMethod = "D"
 
for i in current Folder do
    {
 
        itemType = type i
 
        if( itemType == "Formal")
                {
 
                fullModName = fullName(i)
                modName = name(i)               
                m = edit(fullModName,false)
                x = 0
 
                if (m == null) { //problem detected with opening the module
                        print modName ":\t ERROR - could not open module\n"  
                        continue
                        }     
                
                current = m
 
                if ((exists attribute attrDefName1) && (exists attribute attrDefName2)) {
                        for o in current do {
                                if ((o.attrDefName1"" == "New")||(o.attrDefName1"" == "Modified") && (o.attrDefName3"" == "True")) {
                                        o.attrDefName2 = testMethod                             
                                        x++   //count each change being made
                                        save(m)
                                        }
                                }
                 }
                else {
                        print modName ":\t Does not contain one or both attributes\n"
                        close(m)
                        continue
                        }
 
                close(m)
                print  modName ":\t" x " changes applied\n"
                }
        }

figured out the requirement = true issue. Thanks again

Mathias, will look into your inputs.

Thanks